package org.zoomdev.zoom.dao.impl;

import org.zoomdev.zoom.aop.Getter;
import org.zoomdev.zoom.aop.Setter;
import org.zoomdev.zoom.dao.adapters.EntityField;
import org.zoomdev.zoom.dao.adapters.ResultSetAdapter;
import org.zoomdev.zoom.dao.adapters.StatementAdapter;
import org.zoomdev.zoom.dao.struct.ColumnMeta;

import java.lang.reflect.Field;

public class BeanEntityField extends EntityField {

    private final Getter getter;
    private final Setter setter;
    private final Field field;

    public BeanEntityField(ColumnMeta columnMeta,
                           StatementAdapter statementAdapter,
                           ResultSetAdapter resultSetAdapter,
                           Field field,
                           Getter getter,
                           Setter setter) {
        super(columnMeta, field.getName(), field.getType(), statementAdapter, resultSetAdapter);
        this.getter = getter;
        this.setter = setter;
        this.field = field;
    }

    public Setter getSetter() {
        return setter;
    }

    @Override
    public void set(Object target, Object value) {
        setter.set(target, value);
    }

    @Override
    public Object get(Object target) {
        return getter.get(target);
    }

    public Field getField() {
        return field;
    }
}
